<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.directive</title>
    
</head>
<body>
    <div id="app">
        <input v-focus>
    </div>

</body>
<script src="vue.js"></script>
    <script>
        const vm = new Vue({
            el:'#app',
            directives: {
            focus: {
                // 指令的定义
                inserted: function (el) {
                el.focus()
                }
            }
            }
        })
        // 注册一个全局自定义指令 `v-focus`
        Vue.directive('focus', {
            // 当被绑定的元素插入到 DOM 中时……
            inserted: function (el) {
                // 聚焦元素
                el.focus()
            }
        })
       
    </script>
</html>
